package com.qf.controller;

import com.github.pagehelper.PageInfo;
import com.qf.dto.R;
import com.qf.dto.UserDto;
import com.qf.pojo.User;
import com.qf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/users")
public class UserController {
    private UserService userService;

    @Autowired
    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    @GetMapping("/login")
    public R login(@RequestBody UserDto userDto) {
        User user = userService.login(userDto);
        if (user == null) {
            return R.setError(null);
        }
        return R.setOk(user);
    }

    @PostMapping("/newuser")
    public R addUser(@RequestBody UserDto user){
        System.err.println("============"+user);
        userService.addUser(user);
        return R.setOk(null);
    }
}
